package demo1;

public class test {
    private static boolean isQuit=false;//定义一个成员变量
    public static void main(String[] args) {
        Thread t=new Thread(()->{
while (!isQuit){
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    System.out.println("线程工作中");
}
            System.out.println("线程工作完毕");
        });
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
isQuit=true;
        System.out.println("设置isQuit为true");
    }
}
